<?php 

$pacote = "classes/componentes";
$pathToThis = pathinfo(__FILE__);
$root = substr($pathToThis['dirname'], 0, strlen($pathToThis['dirname']) - strlen($pacote) - 1);

require_once $root."/classes/base/Componente.class.php";

class InputFile extends Componente {

	private $mime = null;

	function InputFile($label, $required = false, $mime = null, $classStyle = "InputFile")
	{
		$this->setLabel($label);
		$this->setObrigatorio($required);
		$this->setConversor(null);
		$this->setClassStyle($classStyle);
		$this->setMime($mime);
	}

	public function render($nome, $form)
	{
		$ret = '<input type="file" id="'.$nome.'" name="'.$nome.'" class="'.$this->getClassStyle().'"';
		if ($this->getMime())
			$ret .= ' accept="'.$this->getMimeAsString.'"';
		if (!$this->getHabilitado())
			$ret .= ' disabled';
		$ret .= ' />';

		return $ret;
	}
	
	public function getValorSetado()
	{
		return "";
	}
	
	public function setMime($mime)
	{
		if(!is_array($mime) || $mime === null)
			return false;
		$this->mime = $mime;
		return true;
	}
	public function getMime()
	{
		return $this->mime;
	}
	public function addMime($mime)
	{
		$this->mime[] = $mime;
	}
	public function getMimeAsString()
	{
		$ret = "";
		$nrMime = count($this->mime);
		for($i = 0; $i < $nrMime; $i++)
		{
			if($ret) $ret .= ",";
			$ret .= $this->mime[$i];
		}
		return $ret;
	}
}
?>